home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / charset / conv.c next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.3 KB  |  131 lines

  1. /* conv.c - Reads a character set from stdin converts and outputs to stdout */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/charset/RCS/conv.c,v 6.0 1991/12/18 20:19:34 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/charset/RCS/conv.c,v 6.0 1991/12/18 20:19:34 jpo Rel $
  9.  *
  10.  * $Log: conv.c,v $
  11.  * Revision 6.0  1991/12/18  20:19:34  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17. #include <isode/general.h>
  18. #include <stdio.h>
  19. #include "charset.h"
  20.  
  21. extern  int        errno;
  22.  
  23. #define    SLEN        256    /* max length in octets of images */
  24. static  CHARSET        *in;
  25. static  CHARSET        *out;
  26. static  int        MnemonicsRequired = FALSE;
  27.  
  28.  
  29. /* -- input args -- */ 
  30. static    char        arg_Iset [SLEN];
  31. static  char        arg_Oset [SLEN];
  32. static  INT16S        arg_Idef = DEFAULT_ESCAPE;
  33. static  INT16S        arg_Odef = DEFAULT_ESCAPE;
  34.  
  35.  
  36.  
  37. main(argc, argv)
  38. int       argc;
  39. char       **argv;
  40. {
  41.     extern int    optind;
  42.     extern char    *optarg;
  43.     int        opt;
  44.     int        len, i;
  45.     CHAR8U        s[SLEN], r[SLEN*4];
  46.  
  47.  
  48.     /* -- initialise -- */
  49.     bzero (arg_Iset, SLEN);
  50.     bzero (arg_Oset, SLEN);
  51.  
  52.  
  53.     while ((opt = getopt (argc, argv, "I:O:i:o:xm")) != EOF)
  54.         switch (opt) {
  55.         case 'x':
  56.             MnemonicsRequired = FALSE;
  57.             break;
  58.         case 'm':
  59.             MnemonicsRequired = TRUE;
  60.             break;
  61.         case 'i':
  62.             (void) strcpy (arg_Iset, optarg);
  63.             break;
  64.         case 'o':
  65.             (void) strcpy (arg_Oset, optarg);
  66.             break;
  67.         case 'I':
  68.             arg_Idef = (INT16S) atoi (optarg);
  69.             break;
  70.         case 'O':
  71.             arg_Odef = (INT16S) atoi (optarg);
  72.             break;
  73.         default:
  74.             print_usage (argv[0]);
  75.         }
  76.  
  77.  
  78.  
  79.     if (arg_Iset[0] == NULL || arg_Oset[0] == NULL)
  80.         print_usage (argv[0]);
  81.  
  82.  
  83.     in  = getchset (arg_Iset, arg_Idef);
  84.     out = getchset (arg_Oset, arg_Odef);
  85.  
  86.     if (in == NULL || out == NULL) {
  87.         fprintf (stderr, "\n\n*** Error: Unknown Charset/s\n\n");
  88.         exit (1);
  89.     }
  90.     
  91.  
  92.     /* should output records of unlimited length by
  93.        outputting one part at a time */
  94.  
  95.  
  96.     while ((len = read (0, s, SLEN)) > 0) {
  97.  
  98.         s[len] = '\0';
  99.         bzero (r, SLEN);
  100.  
  101.         switch (MnemonicsRequired) {
  102.         case TRUE:
  103.             len = strncnv (out,in,r,s,SLEN*4,TRUE);
  104.             break;
  105.         default:    
  106.             len = strncnv (out,in,r,s,len,FALSE);
  107.             break;    
  108.         }
  109.  
  110.         for (i = 0; i < len; i++)
  111.             fprintf (stdout, "%c", r[i]);
  112.     }
  113.  
  114.  
  115.     fflush (stdout);
  116.     exit (0);
  117. }
  118.  
  119.  
  120.  
  121.  
  122. static print_usage (prog)
  123. char    *prog;
  124. {
  125.     fprintf (stderr, "\n\n");
  126.     fprintf (stderr, 
  127.         "Usage:  %s  -i charsetin  -o charsetout  [-x | -m]", prog); 
  128.     fprintf (stderr, "\n\n");
  129.     exit (1);
  130. }
  131.